package cn.iocoder.yudao.module.game.controller.app.bankCard;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.game.controller.admin.bankCard.vo.BankCardPageReqVO;
import cn.iocoder.yudao.module.game.controller.admin.bankCard.vo.BankCardRespVO;
import cn.iocoder.yudao.module.game.controller.admin.bankCard.vo.BankCardSaveReqVO;
import cn.iocoder.yudao.module.game.dal.dataobject.bankCard.BankCardDO;
import cn.iocoder.yudao.module.game.service.bankCard.BankCardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 银行卡")
@RestController
@RequestMapping("/game/bank-card")
@Validated
public class AppBankCardController {

    @Resource
    private BankCardService bankCardService;

    @PostMapping("/create")
    @Operation(summary = "创建银行卡")
    public CommonResult<Long> createBankCard(@Valid @RequestBody BankCardSaveReqVO createReqVO) {
        return success(bankCardService.createBankCard(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新银行卡")
    public CommonResult<Boolean> updateBankCard(@RequestBody BankCardSaveReqVO updateReqVO) {
        bankCardService.updateBankCard(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除银行卡")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteBankCard(@RequestParam("id") Long id) {
        bankCardService.deleteBankCard(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得银行卡")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BankCardRespVO> getBankCard(@RequestParam("id") Long id) {
        BankCardDO bankCard = bankCardService.getBankCard(id);
        return success(BeanUtils.toBean(bankCard, BankCardRespVO.class));
    }

    @PostMapping("/list")
    @Operation(summary = "获得银行卡分页")
    public CommonResult<List<BankCardDO>> list(@RequestBody BankCardPageReqVO params) {
        List<BankCardDO> pageResult = bankCardService.getBankCardList(params);
        return success(pageResult);
    }

    @GetMapping("/page")
    @Operation(summary = "获得银行卡分页")
    public CommonResult<PageResult<BankCardRespVO>> getBankCardPage(@Valid BankCardPageReqVO pageReqVO) {
        PageResult<BankCardDO> pageResult = bankCardService.getBankCardPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, BankCardRespVO.class));
    }

}